<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8" import="com.ckeditor.CKEditorConfig"%>
<html>
<head>
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor"%>
<%@ include file="/jsp/include/header.jsp"%>
<%
	CKEditorConfig config2 = new CKEditorConfig();
	config2.addConfigValue("toolbar","[['Bold', 'Italic','Underline','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']]");
	config2.addConfigValue("height", 100);
	config2.addConfigValue("width", 430);
	config2.addConfigValue("toolbarCanCollapse", false);
%>
<script type="text/javascript" charset="UTF-8">
	var dg1;
	var dg2;
	var d1;
	var d2;
	var f1;
	$(function() {

		f1 = $('#f1').form({
			onLoadSuccess:function(data){
				var oEditor = CKEDITOR.instances.contact_desc;
				var value = $("textarea[name=contact_desc]").val();
				oEditor.setData(value);
			}
		});
 
		d1 = $('#d1').show().dialog({
			modal : true,
			title : '需求',
			//fit:true,
			buttons : [ {
				text : '确定',
				handler : function() {
					var oEditor = CKEDITOR.instances.contact_desc;
					$("textarea[name=contact_desc]").val(oEditor.getData());
					var data=JSON.stringify(f1.form("serialize"));
					$("input[name=data]").val(data);
					f1.form('submit', {
						url : '<%=ctx%>/demand/contact/save.htm',
						success : function() {
							try {
								d1.dialog('close');
								$.messager.show({
									msg : '操作成功！',
									title : '提示'
								});
								dg1.datagrid('reload');
							} catch (e) {
								$.messager.show({
									msg : '操作失败！',
									title : '提示'
								});
							}
						}
					});
					 
				}
			},{
				text : '取消',
				handler : function() {
					d1.dialog('close');
				}
			} 
			]
		}).dialog('close');
		dg1 = $('#dg1').datagrid({
			url : '<%=ctx%>/demand/contact/list.htm',
			toolbar : '#toolbar',
			title : '需求',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 10,
			pageList : [10,20,50],
			fit : true,
			//fitColumns : true,
			nowrap : false,
			border : true,
			//width:pageWidth()-22,
			idField : 'contact_id',
			frozenColumns : [ [ {
				field : 'contact_id',
				width : 50,
				checkbox : true
			},
			{
				field : 'contact_num',
				title : '需求编号',
				width : 100
			},
			{
				field : 'contact_title',
				title : '需求标题',
				width : 100
			},
			{
				field : 'contact_type1_',
				title : '需求类型',
				width : 100
			}] ],
			columns : [ [ 
			{
				field : 'contact_type2_',
				title : '是否合同内',
				width : 80
			},
			{
				field : 'sys_id_',
				title : '需求所属系统',
				width : 100
			},
			{
				field : 'contact_code',
				title : 'IT网管需求编码',
				width : 100
			},
			{
				field : 'contact_from',
				title : '需求来源部门或联系方式',
				width : 100
			},
			{
				field : 'plan_month',
				title : '需求月份',
				width : 100
			},
			{
				field : 'state_',
				title : '任务状态',
				width : 100
			},
			{
				field : 'state',
				hidden:true
			},
			{
				field : 'owner',
				hidden:true
			},
			{
				field : 'owner_',
				title : '需求负责人',
				width : 100
			},
			{
				field : 'work_day',
				title : '工作量 人工/日',
				width : 100
			},
			{
				field : 'create_date',
				title : '文档创建时间',
				width : 80
			},
			{
				field : 'record_date',
				title : '需求登记时间',
				width : 80
			},
			{
				field : 'plan_date',
				title : '计划完成时间',
				width : 80
			},
			{
				field : 'finished_date',
				title : '实际完成时间',
				width : 80
			}
			] ],
			queryParams:{
				queryParam : '${param.queryParam}'
			},
			onDblClickCell: function(index,field,value){
				var rows = dg1.datagrid('getRows');
				parent.addTabFun({
					src : "<%=ctx%>/jsp/demand/contactCfg.jsp?contactId="+rows[index].contact_id,
					title :rows[index].contact_num
				});
				
			}
		});
		
		<%--
		$('select[name=meeting_id]').combogrid({
			panelWidth:300,
			required:true,
			idField:'meeting_id',
			textField:'meeting_name',
			url:'<%=ctx%>/sys/paramGroup/getParamGrid.htm?info=ANJDndi6OZ',
			columns:[[
				{field:'meeting_id',title:'ID',width:60,hidden : true},
				{field:'meeting_name',title:'会议名称',width:100},
				{field:'meeting_type_',title:'类型',width:80},
				{field:'meeting_date',title:'时间',width:80}
				
			]]
		});
		
		var state=$('select[name=state]');
		state.combobox({
			editable:false,
			valueField:'code',
			textField:'code_desc',
			url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=d_contact&info=state',
			onLoadSuccess:function(){
				if(typeof($(this).combobox("getData")[0])!="undefined"){
					$(this).combobox("setValue",$(this).combobox("getData")[0].code);
					//$('#dg1').datagrid({url : '<%=ctx%>/demand/contact/list.htm?state=1'}); 
					//searchFun();
				}
			}
		})
		--%>
		 

	});

	function append() {
		d1.dialog('open');
		f1.form('clear');
	}

	function edit() {
		var rows = dg1.datagrid('getChecked');
		if (rows.length != 1 && rows.length != 0) {
			var names = [];
			for ( var i = 0; i < rows.length; i++) {
				names.push(rows[i].name);
			}
			$.messager.show({
				msg : '只能择一个记录编辑！您已经选择了【' + names.join(',') + '】' + rows.length + '条',
				title : '提示'
			});
		} else if (rows.length == 1) {
			if(rows[0].state=="3"){//已完成不可修改
				$.messager.show({
					msg : "需求编号："+rows[0].contact_num+"已完成，不可修改",
					title : '提示'
				});
				return false;
			}
			d1.dialog('open');
			f1.form('clear');
			f1.form('load','<%=ctx%>/demand/contact/get.htm?id='+rows[0].contact_id);
			
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	
	function remove() {
		var ids = [];
		var rows = dg1.datagrid('getChecked');
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].contact_id);
						if(rows[i].state=="3"){//已完成不可修改
							$.messager.show({
								msg : "需求编号："+rows[i].contact_num+"已完成，不可删除",
								title : '提示'
							});
							return false;
						}
					}
					$.ajax({
						url : '<%=ctx%>/demand/contact/del.htm',
						data : {
							id : ids.join(',')
						},
						cache : false,
						success : function(response) {
							dg1.datagrid('unselectAll');
							dg1.datagrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}

	function searchFun() {
		//var aa=$('#toolbar input[name=state]')
		//	alert(aa.combobox('getData')[0].code);
		dg1.datagrid('load', {
			key : $('#toolbar input[name=key]').val(),
			contact_num : $('#toolbar input[name=contact_num]').val(),
			sys_id : $('#toolbar input[name=sys_id]').val(),
			contact_code : $('#toolbar input[name=contact_code]').val(),
			state : $('#toolbar input[name=state]').val(),
			owner : $('#toolbar input[name=owner]').val(),
			plan_month : $('#toolbar input[name=plan_month]').val()
		});
	}
	function clearFun() {
		$('#toolbar input').val('');
		dg1.datagrid('load', {});
	}
	function sendMail() {
		var rows = dg1.datagrid('getChecked');
		if(rows.length == 1) {
			dg2 = $('#dg2').datagrid({
				url : '<%=ctx%>/sys/paramGroup/getParamGrid.htm?info=UGxosPAiph',
				pagination : true,
				pageSize : 50,
				pageList : [20],
				fitColumns : true,
				nowrap : false,
				border : false,
				width:400,
				height:300,
				idField : 'ur_id',
				frozenColumns : [ [ {
					field : 'ur_id',
					width : 50,
					checkbox : true
				}, {
					field : 'user_name',
					title : '名字',
					width : 100,
					sortable : true
				}] ],
				columns : [ [ 
				{
					field : 'email',
					title : '邮箱',
					width : 100
					 
				}] ],
				onLoadSuccess:function(data){
					var dg2Rows=dg2.datagrid("getRows");
					for(var i=0;i<dg2Rows.length;i++){
						if(dg2Rows[i].ur_id==rows[0].owner){
							dg2.datagrid("checkRow",i);
						}else{
							dg2.datagrid("uncheckRow",i);
						}
					}
				}
			});
			d2 = $('#d2').show().dialog({
				modal : true,
				title : '选择邮箱',
				buttons : [ {
					text : '确定',
					handler : function() {
						var rows = dg2.datagrid('getSelections');
						 if(rows.length==0){
							 $.messager.show({
									msg : '请至少选择一个邮箱进行发送',
									title : '提示'
							 });
						 }else{
							 var contact = dg1.datagrid('getChecked');
							 var data="";
							 for(i=0;i<rows.length;i++){
								 data+=rows[i].email;
								 if(i!=rows.length-1)
									 data+=",";
							 }
							 data="{'id':'"+contact[0].contact_id+"',maillist:'"+data+"'}";
							 $.ajax({
									url : '<%=ctx%>/demand/contact/sendMail.htm',
									type: "POST",
									data:{data:data},
									cache : false,
									dataType:"text",
									success : function(v) {
										if(v==0){
											$.messager.show({
												title : '提示',
												msg : '发送失败！'
											});
										}else{
											$.messager.show({
												title : '提示',
												msg : '操作成功！'
											});
										}
										d2.dialog('close');
									}
							 });
						 }
						
					}
				},{
					text : '取消',
					handler : function() {
						d2.dialog('close');
					}
				} 
				]
			});
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	function print() {
		var rows = dg1.datagrid('getChecked');
		if(rows.length == 1) {
			window.open(ctx+"/demand/contact/print.htm?id="+rows[0].contact_id,"_blank");
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	function pageWidth(){
	    if($.browser.msie){
	        return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth :
	        document.body.clientWidth;
	    }else{
	        return self.innerWidth;
	    }
	}; 
</script>
</head>
<body class="easyui-layout"  >
<div data-options="region:'center',border:false"   style="overflow: hidden;" >
		<div id="toolbar" class="datagrid-toolbar" style="height: auto;">
			<fieldset>
				<legend>查询</legend>
				<table class="tableForm">
					<tr> <th>需求标题</th>
						<td><input name="key" style="width: 120px;" />
						</td>
						<th>需求编号</th><td><input name="contact_num" style="width: 120px;" /></td>
						<th>IT网管需求编号 </th><td>
						<input name="contact_code" style="width: 120px;" />
						</td>
						<td colspan="2">
						<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchFun();" href="javascript:void(0);">查找</a>
							<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="clearFun();" href="javascript:void(0);">清空</a>
						</td>
					</tr>
					<tr> 
					<th>需求月份 </th><td>
						<select id="plan_month" name="plan_month"  style="width: 120px;" class="easyui-combobox"  
                    			 data-options="editable:false,
                    			 			   valueField:'ym',
                    			 			   textField:'ym',
                    			 			   url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=gdWLWYl9P4'">
                	</select>
					</td>
						<th>状态</th><td>
							<select  name="state" style="width: 120px;" class="easyui-combobox"   
								data-options="editable:false,
								valueField:'code',
								textField:'code_desc',
								url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=d_contact&info=state',
								onLoadSuccess:function(){
									if(typeof($(this).combobox('getData')[0])!='undefined'){
										
									}
								}"></select>
								<%--
									$(this).combobox('setValue',$(this).combobox('getData')[0].code);
								 --%>
						</td>
						<th>需求负责人</th><td>
						<select name="owner"  style="width: 120px;" class="easyui-combogrid"  
                    			 data-options="idField:'ur_id',
												textField:'user_name',
												url:'<%=ctx%>/sys/paramGroup/getParamGrid.htm?info=UGxosPAiph',
												columns:[[
													{field:'ur_id',title:'ID',width:10,hidden : true},
													{field:'user_name',title:'名称',width:100}
													
												]]">
               			 </select>
						</td>
						<th>所属系统</th><td>
						<select name="sys_id"  style="width: 120px;" class="easyui-combobox"  
                    			 data-options="editable:false,
                    			 			   valueField:'code',
                    			 			   textField:'code_desc',
                    			 			   url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=d_contact&info=sys_id'">
               			 </select>
						</td>
					</tr>
					
				</table>
			</fieldset>
			<%--管理员可操作 --%>
			<c:if test="${userRoleInfo.role_id eq '1'}">
			<div>
				<a class="easyui-linkbutton" iconCls="icon-add" onclick="append();" plain="true" href="javascript:void(0);">增加</a>
				<a class="easyui-linkbutton" iconCls="icon-remove" onclick="remove();" plain="true" href="javascript:void(0);">删除</a> 
				<a class="easyui-linkbutton" iconCls="icon-edit" onclick="edit();" plain="true" href="javascript:void(0);">编辑</a>
				<a class="easyui-linkbutton" iconCls="icon-undo" onclick="dg1.datagrid('unselectAll');" plain="true" href="javascript:void(0);">取消选中</a>
				|
				<a class="easyui-linkbutton" iconCls="icon-mail" onclick="sendMail();" plain="true" href="javascript:void(0);">发送邮件</a>
				<a class="easyui-linkbutton" iconCls="icon-print" onclick="print();" plain="true" href="javascript:void(0);">打印</a>
			</div>
			</c:if>
			<%--管理员可操作 --%>
		</div>
		<table id="dg1"></table>
		
    <div id="d1" style="display: none;width:660;overflow: hidden;">
		<form id="f1" method="post">
		 <input name="contact_id" type="hidden" />
		 <input name="data" type="hidden" />
		 <table class="tableForm">
		     <tr>
 				<td style="width:70px;" >需求编号：</td>
			    <td style="width:150px;" title="系统自动生成">    
				<input name="contact_num" readonly="readonly" style="background-color:khaki" />
			    </td>
			   
				<td style="width:70px;" >需求类型：</td>
			    <td style="width:150px;">
				<select name="contact_type1"  style="width: 150px;" class="easyui-combobox"  
                    			 data-options="editable:false,
											   required:true,
                    			 			   valueField:'code',
                    			 			   textField:'code_desc',
                    			 			   url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=d_contact&info=contact_type1'">
             	</select> 
			    </td>
			</tr>
			<tr>
				 <td style="width:70px;" >需求标题：</td>
			    <td style="width:150px;">    
				<input name="contact_title" class="easyui-validatebox" data-options="validType:'maxLength[100]'" required="true"/>
			    </td>
				<td style="width:70px;" >是否合同内：</td>
			    <td style="width:150px;">    
				<select name="contact_type2"  style="width: 150px;" class="easyui-combobox"  
                    			 data-options="editable:false,
											   required:true,
                    			 			   valueField:'code',
                    			 			   textField:'code_desc',
                    			 			   url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=comm&info=yes_no'">
                </select>
			    </td>
		     </tr>
		     <tr>
			   	  <td style="width:70px;" >IT网管需求编码：</td>
			    <td style="width:150px;">    
				<input name="contact_code" class="easyui-validatebox" data-options="validType:'maxLength[20]'"  required="true"/>
			    </td>
				 <td style="width:70px;" >需求来源：</td>
			    <td style="width:150px;">    
				<input name="contact_from" class="easyui-validatebox" data-options="validType:'maxLength[100]'"  required="true"/>
			    </td>
			 </tr>
			 <tr>
	 
			   <td style="width:70px;" >所属系统：</td>
			   <td style="width:150px;">
			    <select name="sys_id"  style="width: 150px;" class="easyui-combobox"  
                    			 data-options="editable:false,
											   required:true,
                    			 			   valueField:'code',
                    			 			   textField:'code_desc',
                    			 			   url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=OS4cqbVroP&info=d_contact&info=sys_id'">
                </select>
			    </td>

				<td style="width:70px;" >需求登记时间：</td>
			    <td style="width:150px;">    
				<input name="record_date"  class="easyui-datebox" style="width: 150px;" editable="false"  required="true"/>
			    </td>
			</tr>
			<tr>	
			    <td style="width:70px;" >需求负责人：</td>
			    <td style="width:150px;">
				<select name="owner"  style="width: 200px;" class="easyui-combogrid"  
                    			 data-options="idField:'ur_id',
												textField:'user_name',
												required:true,
												editable:false,
												url:'<%=ctx%>/sys/paramGroup/getParamGrid.htm?info=UGxosPAiph',
												columns:[[
													{field:'ur_id',title:'ID',width:60,hidden : true},
													{field:'user_name',title:'名称',width:80},
													{field:'role_name',title:'角色',width:80}
													
												]]">
               			 </select>
			    </td>
			     <td style="width:70px;" >需求月份：</td>
			    <td style="width:150px;">    
			    <select name="plan_month"  style="width: 150px;" class="easyui-combobox"  
                    			 data-options="editable:false,
											   required:true,
                    			 			   valueField:'ym',
                    			 			   textField:'ym',
                    			 			   url:'<%=ctx%>/sys/paramGroup/getParam.htm?info=gdWLWYl9P4'">
                </select>
			    </td>
		     </tr>
		     <tr>
				<td style="width:70px;" >计划完成时间：</td>
			    <td style="width:150px;">    
				<input name="plan_date"    class="easyui-datebox" style="width: 150px;" editable="false"   required="true"/>
			    </td>
				<td style="width:70px;" >工作量 人工/日：</td>
			    <td style="width:150px;">    
				<input name="work_day" class="easyui-validatebox" data-options="required:true,validType:'maxLength[4]'"   />
			    </td>
			  </tr>
			  <tr>
			   <td style="width:70px;" >需求描述：</td>
			    <td style="width:430;height:150" colspan="3" >
				<textarea name="contact_desc" ></textarea>
			    <ckeditor:replace replace="contact_desc"  config="<%=config2 %>"  basePath="${pageScope.ctx}/ckeditor/"/>
			    </td>
		     </tr>
      </table>
  </form>
 </div>  
 
  <div id="d2"   style="display: none;overflow: hidden;">
  	<table id="dg2"></table>
  </div>
</div>
</body>
</html>